package com.cn.boot.student.controller.rbac;

import com.cn.boot.student.entity.UserRoleRelationEntity;
import com.cn.boot.student.service.rbac.IUserRoleRelationService;
import com.cn.boot.student.util.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户角色关系控制器
 */
@RestController
@Api(tags = "用户角色关系管理")
@RequestMapping("/admin/urr")
public class UserRoleRelationController {
    @Autowired
    private IUserRoleRelationService iUrr;

    @PostMapping("/add")
    @PreAuthorize("hasAuthority('sys:permission:add')")
    @ApiOperation(value = "关系添加")
    public CommonResult add(UserRoleRelationEntity urr){
        return iUrr.add(urr);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('sys:permission:update')")
    @ApiOperation(value = "关系更新")
    public CommonResult update(UserRoleRelationEntity urr){
        return iUrr.update(urr);
    }

    @DeleteMapping("/del")
    @PreAuthorize("hasAuthority('sys:permission:del')")
    @ApiOperation(value = "关系删除")
    public CommonResult del(Integer id){
        return iUrr.del(id);
    }

    @PostMapping("/findAll")
    @PreAuthorize("hasAuthority('sys:permission:read')")
    @ApiOperation(value = "关系查询")
    public CommonResult findAll(){
        return iUrr.findAll();
    }
}
